{% extends 'base.html' %}
{% from "bootstrap/pagination.html" import render_pagination %}

{% block title %}
       {{ current_user.realname }}{{ title }}
          
{% endblock %}
{% block content %}

    <div class="container">
        <a href="{{ url_for('main.new') }}" class="btn btn-primary">添加日报</a>
        <a href="{{ url_for('main.export') }}" class="btn btn-primary">导出日报</a>
    </div>

    <div class="container"  style="width:1200px;">
        <div class=table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>事项</th>
                <th>事项详情</th>
                <th>状态</th>
                <th>计划完成时间</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                {% for daily in dailys %}
                <tr>
                    <td> {{ daily.item }} </td>
                    <td> {{ daily.detail }} </td>
                    <td> {{ daily.status }} </td>
                    <td> {{ daily.finsh_time  }} </td>
                    <td> {{ daily.update_time | dateformat("%Y-%m-%d %H:%M:%S") }} </td>
                    <td> <a href="{{ url_for('main.daily', id=daily.id) }}">修改</a>
                        |<a href="javascript:void(0)" url="{{ url_for('main.delete', id=daily.id) }}" onclick="daily_del(this)">删除</a></td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        </div>



        {% if pagination %}
            {{ render_pagination(pagination) }}
        {% endif %}
    </div>
{% endblock %}

{% block scripts %}
 {{ super() }}
<script type="text/javascript">
    function daily_del (obj) {
        $.confirm({
            title: '提示！',
            content: '确认删除后内容无法恢复!',
            buttons: {
                    ok: {
                        text: "确定",
                        btnClass: 'btn-danger',
                        keys: ['enter'],
                        action: function(){
                            var url = ($(obj).attr("url"));
                            $.ajax({
                                url: url,
                                type: "DELETE",
                                dataType: "json"
                            })
                                .done(function(data) {
                                    if (data.msg === 'success') {
                                        var b = obj.parentNode.parentNode;
                                        b.parentNode.removeChild(b);
                                }
                                })
                                    .fail(function(xhr) {
                                        console.log(xhr.status);
                                    });

                        }
                    },
                    cancel: {
                        text: "取消",
                        btnClass: 'btn-primary',
                        keys: ['esc']
                        /*action:function () {
                            alert("你点击了取消按钮！")
                        }*/

                    }
                }

        });

        };

</script>

{% endblock %}
